//package com.yunxin.core.utils.infra.support.request.merchant;
//
//import org.springframework.beans.BeansException;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.stereotype.Component;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Objects;
//import java.util.Optional;
//
///**
// * @author zero°
// * @since 2024-01-03
// */
//@Component
//public class MerchantActionFactory implements ApplicationContextAware {
//
//    private static final Map<Long, MerchantActionListener> SERVICE_MAP = new HashMap<>();
//
//
//
//
//    //公共api下游
//    private static CommonApiActionListener commonApiActionListener = null;
//
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        //获取所有MerchantActionListener类型的类
//        Map<String, MerchantActionListener> map = applicationContext.getBeansOfType(MerchantActionListener.class);
//        map.forEach((key, value) -> Optional.ofNullable(value.merchantId())
//                .ifPresent(service -> SERVICE_MAP.put(value.merchantId(), value)));
//        commonApiActionListener = applicationContext.getBean(CommonApiActionListener.class);
//
//    }
//
//    /**
//     * 获取 MerchantActionListener
//     * @param merchantId merchantId
//     * @return MerchantActionListener
//     */
//    public BaseActionListener getMerchantActionListener(Long merchantId) {
//
//        if (Objects.isNull(merchantId)) {
//            return null;
//        }
//
//        //能走到这一步说明肯定是api产品,MerchantActionListener为null说明不是单独对接的下游,
//        BaseActionListener merchantActionListener = SERVICE_MAP.get(merchantId);
//        if (Objects.isNull(merchantActionListener)) {
//            boolean b = commonApiActionListener.checkExists( merchantId);
//            if (b) {
//                return commonApiActionListener;
//            }
//        }
//        return merchantActionListener;
//    }
//
//}
